var options_ajaxform_authorization_box = { 
    target: '#authorization_box',
    success: function(data, status) {
    	var studentid = $('#authorization_box').find("[name=object_id]")[0].value;
    	update_student_row(studentid);
    	hijax_authorization_form();
    },
}; 

/* Look for the one or two forms in the authorization box
	and make them ajax.
*/
function hijax_authorization_form() {
	var names = ['add_group', 'remove_group'];
	for(var i=0; i<names.length; i++){
		var f = $("#"+names[i]);
		f.ajaxForm(options_ajaxform_authorization_box);
		hijax_form(f);
	}
}

/* Make the edit link ajax
*/
function hijax_edit_link() {
	$("#student_edit_link").click(function() {
		var link = $(this);
		var url = link.attr("href") + "?ajax=true";
		$.get(url, function(data){
			link.hide();
			$("#student_info_wrapper").replaceWith(data);
			
			hijax_student_edit_form();
		});
		return false;
   });
   /* The edit page needs some css and javascript, we load them now: */
   /* TODO: Rethink it and make js and css inclusion easier for programmer! */
   /*
   $.ajax({
  		type: "GET",
		url: "/javascripts/validation/editstudent.js",
  		dataType: "script"
	});*/
}

$(document).ready(function() {
	hijax_authorization_form();
	hijax_edit_link();
});
